{layout name="public::layout" /}
<ul class="nav nav-pills pull-left" role="tablist">
  <li>
     <button type="submit" class="btn btn-danger" form="major_form" onClick="return window.confirm('您确定删除所选记录吗？')" >删除</button>
  </li>
  <li>
      <button type="button" class="btn btn-info"  onclick="history.go(0)">刷新</button>
  </li>
  <li>
     <button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal">添加</button>
  </li>
  <li>
      <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#excel">Excel导入</button>
  </li>
  <li>
      <button type="button" class="btn btn-warning"><a href="{:url('admin/Major/output')}">导出</a></button>
  </li>
  <li>
      <button type="button" class="btn btn-info" onclick="history.go(-1)">返回</button>
  </li>
</ul>

<form class="navbar-form navbar-right pull-right" action="{:url('admin/Major/searchform')}" method="post">
        <div class="form-group">
          <input type="text" class="form-control" placeholder="Search" name="searchname">
        </div>
        <div class="form-group">
            <select class="form-control" name="form">
              <option value="major">专业名称</option>
              <option value="campus">院系</option>
              <option value="major_number">专业编号</option>
              <option value="major_code">国际专业代码</option>
            </select>
    </div>
        <button type="submit" class="btn btn-default">搜索</button>
</form>
<br>
<br>

<h2 class="text-center text-success">专业信息管理列表({$form}关键字：{$searchname})</h2>
<table class="table table-hover">
    <form action="{:url('admin/Major/delete')}" method="post" id="major_form">
    <thead class="lead">
        <tr>
            <td><input type="checkbox"  name="chkAll" onclick="chkAll_onclick(this)" />全选</td>
            <td>id</td>
            <td>专业名称</td>
            <td>院系</td>
            <td>专业编号</td>
            <td>国标专业代码</td>
            <td>学制</td>
            <td>培养层次</td>
            <td>所属学科</td>
            <td>状态</td>
            <td>创建时间</td>
            <td colspan="2">操作</td>
        </tr>
    </thead>
    
    {volist name="majorInfo" id="major"}
    <tr>
        <td><input type="checkbox" name="ids[]" value="{$major.id}" ></td>
        <td>{$major.id}</td>
        <td>{$major.major}</td>
        <td>{$major.department_id}</td>
        <td>{$major.major_number}</td>
        <td>{$major.major_code}</td>
        <td>{$major.learning}</td>
        <td>{$major.level}</td>
        <td>{$major.subject}</td>
        <td>
            {eq name="$major->getdata('status')" value="1"}
            <span class="glyphicon glyphicon-ok-circle" style="color:green;">启用</span>
            {else/} 
            <span class="glyphicon glyphicon-remove-circle" style="color:red;">禁用</span>
            {/eq}
        </td>
        <td>{$major.create_time}</td>
        <td>
            <a href="{:url('admin/Major/majorEdit',['id'=>$major.id])}">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
            </a>
        </td>      
<!--  将a标签的默认行为取消有两种方法：1，在href中写javascript:;  2,在onclick的函数后面写;return false, 建议用第二种方法-->
        <td>
            <a href="javascript:;" onClick="dele()">
                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
            </a>
        </td>       
    </tr>
    {/volist}
    </form>
</table>
<div class="text-center">{$majorInfo|raw} </div>
<!-- 添加数据的模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">添加数据</h4>
      </div>
      <div class="modal-body">
<!--          表单数据-->
       <form class="form-horizontal" method="post" id="login" > 
        <div class="form-group">
          <label for="major" class="col-sm-2 control-label">专业名称:</label>
          <div class="col-sm-8">
            <input type="text" name="major" class="form-control" id="major" placeholder="请输出专业名" onBlur="checkname()">
          </div>
            <label for="major" class="error" style="color: red;"></label>
            <div class="col-sm-2" id="nameCheckMessages" style="color: red;font-size: 130%;font-weight: 500"></div>
        </div>
        <div class="form-group">
          <label for="department" class="col-sm-2 control-label">院系:</label>
          <div class="col-sm-8">
            <select class="form-control" name="department" id="department">
                 {volist name="$departmentList" id="department"}
                  <option value="{$department.id}">{$department.name}</option>
                 {/volist}
            </select>
          </div>
        </div>
           <div class="form-group">
          <label for="major_number" class="col-sm-2 control-label">专业编号:</label>
          <div class="col-sm-8">
            <input type="text" name="major_number" class="form-control" id="major_number" placeholder="请输出专业编号">
          </div>
               <label for="major_number" class="error" style="color: red;"></label>
        </div>
           <div class="form-group">
          <label for="major_code" class="col-sm-2 control-label">国际专业代码:</label>
          <div class="col-sm-8">
            <input type="text" name="major_code" class="form-control" id="major_code" placeholder="请输出国际专业代码">
          </div>
               <label for="major_code" class="error" style="color: red;"></label>
        </div>
           <div class="form-group">
          <label for="learning" class="col-sm-2 control-label">学制:</label>
          <div class="col-sm-8">
            <input type="number" name="learning" class="form-control" id="learning" placeholder="请输出学制">
          </div>
               <label for="learning" class="error" style="color: red;"></label>
        </div>
           <div class="form-group">
          <label for="level" class="col-sm-2 control-label">培养层次:</label>
          <div class="col-sm-8">
              <select class="form-control" name="level" id="level">
                  <option value="本科">本科</option>
                  <option value="专科">专科</option>
                  <option value="专升本">专升本</option>
                  <option value="其他">其他</option>
              </select>         
          </div>
        </div>
           <div class="form-group">
          <label for="subject" class="col-sm-2 control-label">所属学科:</label>
          <div class="col-sm-8">
            <select class="form-control" name="subject" id="subject">
                  <option value="医学">医学</option>
                  <option value="工学">工学</option>
                  <option value="教育学">教育学</option>
                  <option value="文学">文学</option>
                  <option value="法学">法学</option>
                  <option value="理学">理学</option>
                  <option value="管理学">管理学</option>
                  <option value="经济学">经济学</option>
                  <option value="艺术学">艺术学</option>
              </select>
          </div>
        </div>
           <div class="form-group">
          <label for="status" class="col-sm-2 control-label">状态：</label>
            <div class="col-sm-8">
              <select class="form-control" name="status" id="status">
                  <option value="1">启用</option>
                  <option value="0">禁用</option>
                </select>
            </div>
        </div>
           <div class="form-group">
               <div class="col-sm-2">
               </div>
               <div class="col-sm-8">
                   <input type="submit" class="btn btn-primary" value="提交">
               </div>      
           </div>
      </form>
     </div>
    </div>
  </div>
</div>

<!--导入Excel的模态框-->
<div class="modal fade" id="excel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-sm" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">添加数据</h4>
      </div>
      <div class="modal-body">
          <a href="{:url('admin/Major/templateDown')}" class="btn btn-default">模板下载</a>
          <hr>
<!--          表单数据-->
        <form action="{:url('excel/Index/major')}" method="post" enctype="multipart/form-data">
          <div class="form-group">
            <label for="file">File input</label>
            <input type="file" id="file" name="file">
            <p class="help-block">可以选择的文件后缀为xlxs、xls、csv</p>
          </div>
          <button type="submit" class="btn btn-default">Submit</button>
        </form>
     </div>
    </div>
  </div>
</div>

<!--jquery验证数据-->
<script src="/static/jQuery_validate/lib/jquery.js"></script>
<script src="/static/jQuery_validate/lib/jquery.mockjax.js"></script>
<script src="/static/jQuery_validate/dist/jquery.validate.js"></script>


<!--a标签的响应事件-->
<script>
//    验证并ajax方式提交数据
$( "#login" ).validate({
  rules: {
    major: "required",
    major_number: "required",
    major_code: "required",
    learning: "required",
    level: "required",
    subject: "required"
  },
  messages:{
    major:"请输入专业名称信息",
    major_number:"请输入专业编号",
    major_code:"请输入国际专业代码",
    learning:"请填写1~10的数",
    level:"请输入层次信息",
    subject:"请输入所属学科",
  },
    submitHandler:function()
    {
        $.ajax({
                  type: 'POST',
                  url: "{:url('admin/Major/insertMajor')}",
                  data: $('#login').serialize(),
                  dataType: 'json',
                  success: function(data){
                      switch(data.status)
                          {
                              case 1:
                                  alert(data.message);
                                  window.location.href="{:url('admin/Major/index')}";
                                  break;
                              case 0:          
                                  alert(data.message);
                                  window.location.href="{:url('admin/Major/index')}";
                          }
                  },
                  error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('错误');
                     }
              })
    }
});

//    删除
    function dele()
    {
        if(confirm('你真要删除？')==true)
            {
                window.location.href="{:url('admin/Major/doDelete',['id'=>$major.id])}";
            }
    }
    
//全选
    function chkAll_onclick(obj)
    {
      var chks = document.getElementsByName("ids[]");
      for( var i = 0 ; i < chks.length ; i++ )
      {
        chks[i].checked = obj.checked;
      }
    }
    
//    添加专业名称ajax查询是否重复
    function checkname()
    {
        //获取输入框元素
        var nameInput=  document.getElementById("major").value
//        alert(nameInput);
        $.ajax({
                  type: 'POST',
                  url: "{:url('admin/Major/namevalidte')}",
                  data: {"nameInput":nameInput},
                  dataType: 'json',
                  success: function(data){
                      switch(data.status)
                          {
                              case 1:
                                  document.getElementById('nameCheckMessages').innerHTML = data.message;
                                  major.focus();
                                  break;
//                                  有相同名字时
                              case 0:          
                                  document.getElementById('nameCheckMessages').innerHTML = data.message;
                          }
                  },
                  error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('错误');
                     }
              })
    }

</script>